#!/bin/bash

# postinst script for system-file-system-nfs
#
# see: dh_installdeb(1)

#set -e

# summary of how this script can be called:
#        * <postinst> \`configure' <most-recently-configured-version>
#        * <old-postinst> \`abort-upgrade' <new version>
#        * <conflictor's-postinst> \`abort-remove' \`in-favour' <package>
#          <new-version>
#        * <postinst> \`abort-remove'
#        * <deconfigured's-postinst> \`abort-deconfigure' \`in-favour'
#          <failed-install-package> <version> \`removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

PATH=/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin
export PATH

if [ "${BASEDIR:=/}" = "/" ]; then
    BASEDIR=""
else
    BASEDIR_OPT="-b $BASEDIR"
fi

case "$1" in
    configure)
	chown root:bin $BASEDIR/var/nfs
	chown daemon:daemon $BASEDIR/var/nfs/v4_oldstate
	chown daemon:daemon $BASEDIR/var/nfs/v4_state
	chown root:sys $BASEDIR/etc/fs/nfs
	chown root:sys $BASEDIR/lib/svc/manifest/network/nfs
	chown root:sys $BASEDIR/usr/lib/fs/nfs
	chown root:sys $BASEDIR/usr/lib/nfs
	chmod 0555 "$BASEDIR/etc/fs/nfs/mount"
	chown root:bin "$BASEDIR/etc/fs/nfs/mount"
	chmod 0555 "$BASEDIR/lib/svc/method/nfs-client"
	chown root:bin "$BASEDIR/lib/svc/method/nfs-client"
	chmod 0555 "$BASEDIR/lib/svc/method/nlockmgr"
	chown root:bin "$BASEDIR/lib/svc/method/nlockmgr"
	chmod 0555 "$BASEDIR/usr/bin/nfsstat"
	chown root:bin "$BASEDIR/usr/bin/nfsstat"
	chmod 0555 "$BASEDIR/usr/lib/fs/nfs/dfmounts"
	chown root:bin "$BASEDIR/usr/lib/fs/nfs/dfmounts"
	chmod 0555 "$BASEDIR/usr/lib/fs/nfs/dfshares"
	chown root:bin "$BASEDIR/usr/lib/fs/nfs/dfshares"
	chmod 0555 "$BASEDIR/usr/lib/fs/nfs/showmount"
	chown root:bin "$BASEDIR/usr/lib/fs/nfs/showmount"
	chmod 0555 "$BASEDIR/usr/lib/fs/nfs/umount"
	chown root:bin "$BASEDIR/usr/lib/fs/nfs/umount"
	chmod 0555 "$BASEDIR/usr/lib/nfs/lockd"
	chown root:bin "$BASEDIR/usr/lib/nfs/lockd"
	chmod 0555 "$BASEDIR/usr/lib/nfs/nfs4cbd"
	chown root:bin "$BASEDIR/usr/lib/nfs/nfs4cbd"
	chmod 0555 "$BASEDIR/usr/lib/nfs/nfsmapid"
	chown root:bin "$BASEDIR/usr/lib/nfs/nfsmapid"
	chmod 0555 "$BASEDIR/usr/lib/nfs/statd"
	chown root:bin "$BASEDIR/usr/lib/nfs/statd"
	chmod 0755 "$BASEDIR/usr/lib/nfs/amd64/libmapid.so.1"
	chown root:bin "$BASEDIR/usr/lib/nfs/amd64/libmapid.so.1"
	chmod 0755 "$BASEDIR/usr/lib/nfs/libmapid.so.1"
	chown root:bin "$BASEDIR/usr/lib/nfs/libmapid.so.1"
	chmod 0444 "$BASEDIR/lib/svc/manifest/network/nfs/cbd.xml"
	chown root:sys "$BASEDIR/lib/svc/manifest/network/nfs/cbd.xml"
	chmod 0444 "$BASEDIR/lib/svc/manifest/network/nfs/client.xml"
	chown root:sys "$BASEDIR/lib/svc/manifest/network/nfs/client.xml"
	chmod 0444 "$BASEDIR/lib/svc/manifest/network/nfs/mapid.xml"
	chown root:sys "$BASEDIR/lib/svc/manifest/network/nfs/mapid.xml"
	chmod 0444 "$BASEDIR/lib/svc/manifest/network/nfs/nlockmgr.xml"
	chown root:sys "$BASEDIR/lib/svc/manifest/network/nfs/nlockmgr.xml"
	chmod 0444 "$BASEDIR/lib/svc/manifest/network/nfs/status.xml"
	chown root:sys "$BASEDIR/lib/svc/manifest/network/nfs/status.xml"
	chmod 0555 "$BASEDIR/usr/lib/fs/nfs/nfsfind"
	chown root:sys "$BASEDIR/usr/lib/fs/nfs/nfsfind"
	[ -f $BASEDIR/etc/default/nfs ] || cp -ax $BASEDIR/usr/share/doc/system-file-system-nfs/examples/nfs $BASEDIR/etc/default/nfs
	chmod 0644 "$BASEDIR/etc/default/nfs"
	chown root:sys "$BASEDIR/etc/default/nfs"
	[ -f $BASEDIR/etc/nfssec.conf ] || cp -ax $BASEDIR/usr/share/doc/system-file-system-nfs/examples/nfssec.conf $BASEDIR/etc/nfssec.conf
	chmod 0644 "$BASEDIR/etc/nfssec.conf"
	chown root:sys "$BASEDIR/etc/nfssec.conf"
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/kernel/fs/amd64/nfs ] && rm -f $BASEDIR/kernel/fs/amd64/nfs
	else
	    chmod 0755 "$BASEDIR/kernel/fs/amd64/nfs"
	    chown root:sys "$BASEDIR/kernel/fs/amd64/nfs"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/kernel/misc/amd64/klmmod ] && rm -f $BASEDIR/kernel/misc/amd64/klmmod
	else
	    chmod 0755 "$BASEDIR/kernel/misc/amd64/klmmod"
	    chown root:sys "$BASEDIR/kernel/misc/amd64/klmmod"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/kernel/misc/amd64/klmops ] && rm -f $BASEDIR/kernel/misc/amd64/klmops
	else
	    chmod 0755 "$BASEDIR/kernel/misc/amd64/klmops"
	    chown root:sys "$BASEDIR/kernel/misc/amd64/klmops"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/kernel/misc/amd64/nfs_dlboot ] && rm -f $BASEDIR/kernel/misc/amd64/nfs_dlboot
	else
	    chmod 0755 "$BASEDIR/kernel/misc/amd64/nfs_dlboot"
	    chown root:sys "$BASEDIR/kernel/misc/amd64/nfs_dlboot"
	fi
	[ "$ZONEINST" = "1" ] || (mkdir -p $BASEDIR/kernel/sys/amd64 && cd $BASEDIR/kernel/sys/amd64 && cp -f ../../../kernel/fs/amd64/nfs nfs)

	chmod 0555 "$BASEDIR/lib/svc/method/nfs-server"
	chown root:bin "$BASEDIR/lib/svc/method/nfs-server"
	chmod 0555 "$BASEDIR/usr/lib/nfs/dtrace/nfs-time.d"
	chown root:bin "$BASEDIR/usr/lib/nfs/dtrace/nfs-time.d"
	chmod 0555 "$BASEDIR/usr/lib/nfs/dtrace/nfs-trace.d"
	chown root:bin "$BASEDIR/usr/lib/nfs/dtrace/nfs-trace.d"
	chmod 0555 "$BASEDIR/usr/lib/nfs/mountd"
	chown root:bin "$BASEDIR/usr/lib/nfs/mountd"
	chmod 0555 "$BASEDIR/usr/lib/nfs/nfsd"
	chown root:bin "$BASEDIR/usr/lib/nfs/nfsd"
	chmod 0555 "$BASEDIR/usr/lib/nfs/nfslogd"
	chown root:bin "$BASEDIR/usr/lib/nfs/nfslogd"
	chmod 0555 "$BASEDIR/usr/lib/nfs/rquotad"
	chown root:bin "$BASEDIR/usr/lib/nfs/rquotad"
	chmod 0555 "$BASEDIR/usr/sbin/exportfs"
	chown root:bin "$BASEDIR/usr/sbin/exportfs"
	chmod 0555 "$BASEDIR/usr/sbin/nfsref"
	chown root:bin "$BASEDIR/usr/sbin/nfsref"
	chmod 0755 "$BASEDIR/usr/lib/fs/nfs/amd64/libshare_nfs.so.1"
	chown root:bin "$BASEDIR/usr/lib/fs/nfs/amd64/libshare_nfs.so.1"
	chmod 0755 "$BASEDIR/usr/lib/reparse/amd64/libnfs_basic.so.1"
	chown root:bin "$BASEDIR/usr/lib/reparse/amd64/libnfs_basic.so.1"
	chmod 0755 "$BASEDIR/usr/lib/reparse/libnfs_basic.so.1"
	chown root:bin "$BASEDIR/usr/lib/reparse/libnfs_basic.so.1"
	chmod 0444 "$BASEDIR/lib/svc/manifest/network/nfs/nfslogd.xml"
	chown root:sys "$BASEDIR/lib/svc/manifest/network/nfs/nfslogd.xml"
	chmod 0444 "$BASEDIR/lib/svc/manifest/network/nfs/rquota.xml"
	chown root:sys "$BASEDIR/lib/svc/manifest/network/nfs/rquota.xml"
	chmod 0444 "$BASEDIR/lib/svc/manifest/network/nfs/server.xml"
	chown root:sys "$BASEDIR/lib/svc/manifest/network/nfs/server.xml"
	[ -f $BASEDIR/etc/default/nfslogd ] || cp -ax $BASEDIR/usr/share/doc/service-file-system-nfs/examples/nfslogd $BASEDIR/etc/default/nfslogd
	chmod 0644 "$BASEDIR/etc/default/nfslogd"
	chown root:sys "$BASEDIR/etc/default/nfslogd"
	[ -f $BASEDIR/etc/nfs/nfslog.conf ] || cp -ax $BASEDIR/usr/share/doc/service-file-system-nfs/examples/nfslog.conf $BASEDIR/etc/nfs/nfslog.conf
	chmod 0644 "$BASEDIR/etc/nfs/nfslog.conf"
	chown root:sys "$BASEDIR/etc/nfs/nfslog.conf"
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/kernel/misc/amd64/nfssrv ] && rm -f $BASEDIR/kernel/misc/amd64/nfssrv
	else
	    chmod 0755 "$BASEDIR/kernel/misc/amd64/nfssrv"
	    chown root:sys "$BASEDIR/kernel/misc/amd64/nfssrv"
	fi
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

    *)
        echo "postinst called with unknown argument '$1'" >&2
        exit 1
    ;;
esac



# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0

